import 'package:flutter/material.dart';

import '../config.dart';
import '../hud.dart';

class HudToast extends StatelessWidget {
  const HudToast({
    super.key,
    required this.text,
    this.indicator,
    required this.position,
  });
  final String text;
  final Widget? indicator;
  final HudPosition position;
  MainAxisAlignment get _alignment {
    if (position == HudPosition.top) {
      return MainAxisAlignment.start;
    }
    if (position == HudPosition.bottom) {
      return MainAxisAlignment.end;
    }
    return MainAxisAlignment.center;
  }

  @override
  Widget build(BuildContext context) {
    return Container(
      margin: const EdgeInsets.all(50),
      padding: const EdgeInsets.symmetric(vertical: 10, horizontal: 8),
      decoration: BoxDecoration(
        color: Colors.black87,
        borderRadius: BorderRadius.circular(5),
      ),
      child: Column(
        mainAxisSize: MainAxisSize.min,
        mainAxisAlignment: _alignment,
        crossAxisAlignment: CrossAxisAlignment.center,
        children: [
          if (indicator != null)
            Container(
              margin: text.isNotEmpty
                  ? Hud.instance.config.textPadding
                  : EdgeInsets.zero,
              child: indicator,
            ),
          if (text.isNotEmpty)
            Text(
              text,
              style: const TextStyle(
                color: Colors.white,
                fontSize: 15,
              ),
            ),
        ],
      ),
    );
  }
}
